package mainBoerse;

import java.util.ArrayList;
import java.util.Collections;

import exceptions.WrongShareName;

public class ShareDepositAccount extends Asset {

	/**
	 */
	
	private ArrayList<ShareItem> wholeStockList;

	public ShareDepositAccount() {

		wholeStockList = new ArrayList<>(); 
	}

	public void createNew(ShareItem newItem) {
		wholeStockList.add(newItem);
		Collections.sort(wholeStockList);
	}

	public void setName(int i, String name) {
		this.wholeStockList.get(i).name = name;
	}

	@Override
	public float getValue() {
		int value = 0;
		for (ShareItem item : wholeStockList) {
			value += item.getValue();
		}
		
		
		this.value = value;
		return value;
	}

	public int getStockCount() {
		return wholeStockList.size();

	}

	/*public void makeWholeStockBigger() {

		ShareItem[] newWholeStock = new ShareItem[this.getStockCount() + 1];

		for (int i = 0; i < this.getStockCount(); i++) {
			newWholeStock[i] = this.wholeStock[i];
		}
	}*/

	public String toString() {
		StringBuilder array = new StringBuilder();
		for (ShareItem item : wholeStockList) {
			array.append(item.toString());
		}
		return array.toString();
	}

	public String getShareName(int number) {
		return this.wholeStockList.get(number).getName();
	}

	public ShareItem getShareItem(int number) {
		return this.wholeStockList.get(number);
	}

	public boolean proofForShareName(String string) throws WrongShareName {
		boolean found = false;

		for (int i = 0; i < this.wholeStockList.size(); i++) {
			if (this.wholeStockList.get(i) != null) {
				if (this.wholeStockList.get(i).getName().equals(string))
					found = true;
			}
		}
		if (!found)
			throw new WrongShareName("Wrong Share name in proofForShareName");
		else
			return found;

	}

}
